﻿using nplJobsCommon.Employeer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using nplJobsCommon.JobSeeker;

namespace nplJobsDAL.Update
{
    public class UpdateJobSeekerResume : DataAccessBase
    {
        public JobSeeker JobSeeker { get; set; }
        public int isSaved = 0;
        public UpdateJobSeekerResume()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertJobSeekerResume.ToString();
        }

        public void invoke()
        {
            JobSeekerResumeDataParameters contactUpdateDataParameters = new JobSeekerResumeDataParameters(this.JobSeeker);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = contactUpdateDataParameters.Parameters;
            dbHelper.RunScalar();

            if (contactUpdateDataParameters.Parameters[2].Value != null)
            {
                isSaved = int.Parse(contactUpdateDataParameters.Parameters[2].Value.ToString());
            }
        }

    }

    #region SQL parameters
    public class JobSeekerResumeDataParameters
    {
        private JobSeeker JobSeeker;
        int isSaved = 0;

        public JobSeekerResumeDataParameters(JobSeeker jobSeeker)
        {
            this.JobSeeker = jobSeeker;
            Build();
        }

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    new SqlParameter("@JobSeekerID", JobSeeker.JobSeekerID),
                    new SqlParameter("@Resume", JobSeeker.Resume),
                    new SqlParameter("@isSaved",isSaved){ Direction =System.Data.ParameterDirection.Output}
                };

            Parameters = parameters;
        }

        public SqlParameter[] Parameters { get; set; }
    }
    #endregion
}


